package izzat.fit.dbservice.controller;

import izzat.fit.dbservice.base.entity.BaseEntity;
import izzat.fit.dbservice.entity.ResponseEntity;
import izzat.fit.dbservice.entity.action.Action;
import izzat.fit.dbservice.service.ActionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @ClassName: ActionDBServiceController
 * @Description: “动作”模块数据库查询接口集
 * @Author: Izzat
 * @Date: 2019-12-31 22:36
 * @Version: v1.0
 */
@RestController
@RequestMapping("db-service/action")
public class ActionDBServiceController {
    @Autowired
    private ActionService actionService;

    @RequestMapping("allAction")
    /** 
    * @Description: 获取所有动作的数据库接口 
    * @Param: [] 
    * @return: izzat.fit.dbservice.entity.ResponseEntity 
    * @Author: Izzat 
    * @Date: 2020/1/3  11:43
    */ 
    public ResponseEntity getAllAction(){
        ResponseEntity response = new ResponseEntity();
        List<Action> serchResult = actionService.getAllAction();
        String info;
        int size = serchResult.size();
        if(size > 0){
            info = "查询成功，为您找到" + size + "条记录";
            response.status(200).datas(serchResult).info(info);
        }else {
            info = "找不到相关记录";
            response.status(400).info(info);
        }
        return response;
    }

    @RequestMapping("findById")
    /**
    * @Description: 按找Id查找动作
    * @Param: [id]
    * @return: izzat.fit.dbservice.entity.action.Action
    * @Author: Izzat
    * @Date: 2019/12/31  23:10
    */
    public ResponseEntity findActionById(@RequestBody int id){
        ResponseEntity response = new ResponseEntity();
        List<Action> serchResult = new ArrayList<>();
        serchResult.add(actionService.findById(id));
        String info;
        int size = serchResult.size();
        if(size > 0){
            info = "查询成功，为您找到" + size + "条记录";
            response.status(200).datas(serchResult).info(info);
        }else {
            info = "找不到相关记录";
            response.status(400).info(info);
        }
        return response;
    }

    @RequestMapping("findByPart")
    /** 
    * @Description: 按照锻炼部位找动作 
    * @Param: [part] 
    * @return: izzat.fit.dbservice.entity.ResponseEntity 
    * @Author: Izzat 
    * @Date: 2020/1/3  11:42
    */ 
    public ResponseEntity findActionByPart(@RequestBody String part){
        ResponseEntity response = new ResponseEntity();
        List<Action> serchResult = actionService.findByPart(part);
        String info;
        int size = serchResult.size();
        if(size > 0){
            info = "查询成功，为您找到" + size + "条记录";
            response.status(200).datas(serchResult).info(info);
        }else {
            info = "找不到相关记录";
            response.status(400).info(info);
        }
        return response;
    }
}
